<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>json (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">json</span>
</div>

<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_json_EvalJsonProcessor.html">
          goog.json.EvalJsonProcessor</a><br/>
        <div class="class-details">A class that parses and stringifies JSON using eval (as implemented in
goog.json).
Adapts <code> goog.json</code> to the <code> goog.json.Processor</code> interface.

</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_json_HybridJsonProcessor.html">
          goog.json.HybridJsonProcessor</a><br/>
        <div class="class-details">Processor form of goog.json.hybrid, which attempts to parse/serialize
JSON using native JSON methods, falling back to goog.json if not
available.
</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_json_NativeJsonProcessor.html">
          goog.json.NativeJsonProcessor</a><br/>
        <div class="class-details">A class that parses and stringifies JSON using the browser's built-in JSON
library, if it is avaliable.

Note that the native JSON api has subtle differences across browsers, so
use this implementation with care.  See json_test#assertSerialize
for details on the differences from goog.json.

This implementation is signficantly faster than goog.json, at least on
Chrome.  See json_perf.html for a perf test showing the difference.

</div>
 </div>
 <div class="fn-constructor">
        <a href="interface_goog_json_Processor.html">
          goog.json.Processor</a><br/>
        <div class="class-details">An interface for JSON parsing and serialization.
</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_json_Serializer.html">
          goog.json.Serializer</a><br/>
        <div class="class-details">Class that is used to serialize JSON objects to a string.
</div>
 </div>
   
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.json.isValid_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">isValid_<span class="args">(<span class="arg">s</span>)</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span>
      </div>


     <div class="entryOverview">
       Tests if a string is an invalid JSON string. This only ensures that we are
not using any invalid characters

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">s</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The string to test.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span>&nbsp;
            True if the input is a valid JSON string.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line43">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.json.parse"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">parse<span class="args">(<span class="arg">s</span>)</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>
      </div>


     <div class="entryOverview">
       Parses a JSON string and returns the result. This throws an exception if
the string is an invalid JSON string.

Note that this is very slow on large strings. If you trust the source of
the string then you should use unsafeParse instead.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">s</span>
        : <span class="type">*</span>
        <div class="entryOverview">The JSON string to parse.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>&nbsp;
            The object generated from the JSON string, or null.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line96">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.json.serialize"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">serialize<span class="args">(<span class="arg">object</span>,&nbsp;<span class="arg">opt_replacer</span>)</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
      </div>


     <div class="entryOverview">
       Serializes an object or a value to a JSON string.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">object</span>
        : <span class="type">*</span>
        <div class="entryOverview">The object to serialize.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">opt_replacer</span>
        : <span>?</span><span class="type">goog.json.Replacer=</span>
        <div class="entryOverview">A replacer function
    called for each (key, value) pair that determines how the value
    should be serialized. By defult, this just returns the value
    and allows default serialization to kick in.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>&nbsp;
            A JSON string representation of the input.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line156">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.json.unsafeParse"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">unsafeParse<span class="args">(<span class="arg">s</span>)</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>
      </div>


     <div class="entryOverview">
       Parses a JSON string and returns the result. This uses eval so it is open
to security issues and it should only be used if you trust the source.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">s</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The JSON string to parse.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>&nbsp;
            The object generated from the JSON string.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line118">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.json.HybridJsonProcessorTest"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">HybridJsonProcessorTest</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_hybridjsonprocessor_test.js.source.html#line20">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.json.Replacer"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">Replacer</span>
        : 
     </div>


     <div class="entryOverview">
       JSON replacer, as defined in Section 15.12.3 of the ES5 spec.

     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line133">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.json.Reviver"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">Reviver</span>
        : 
     </div>


     <div class="entryOverview">
       JSON reviver, as defined in Section 15.12.2 of the ES5 spec.

     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line142">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.json.USE_NATIVE_JSON"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">USE_NATIVE_JSON</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_json.js.source.html#line33">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.json.hybrid"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">hybrid</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_hybrid.js.source.html#line26">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.json.hybridTest"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">hybridTest</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_hybrid_test.js.source.html#line20">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.json.processorTest"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.json.</span><span class="entryName">processorTest</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_json_processor_test.js.source.html#line15">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>
      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Package json</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">Package Reference</h2>
            <div id="sideTypeIndex" rootPath="" current="json"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
